<template>
  <div class="cart">
    <el-table :data="$store.state.cart" border style="width: 100%">
      <el-table-column
        type="index"
        label="序号"
        width="50"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="name"
        label="书名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="price"
        label="价格"
        width="100"
        align="center"
      ></el-table-column>
      <el-table-column label="数量" align="center">
        <template slot-scope="scope">
          <el-input-number
            v-model="scope.row.number"
            :min="1"
            :max="scope.row.pnum"
            label="描述文字"
            @change="change(scope.row.number, scope.$index)"
          ></el-input-number>
        </template>
      </el-table-column>
      <el-table-column label="小计" width="150" align="center">
        <template slot-scope="scope">
          {{ scope.row.lineTotal }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="total_warpper">
      <h3>共计：{{ $store.getters.totalPrice }}</h3>
      <h3>总数：{{ $store.getters.totalNumber }}</h3>
    </div>
  
    <label for="">收货人姓名：</label>
    <el-input type="text"  v-model="receiver.name"></el-input>
    <label for="">收货人电话：</label>
    <el-input type="number" v-model="receiver.phone"></el-input>
    <label for="">收货人地址：</label>
    <el-input type="text" v-model="receiver.adderss"></el-input>
      <div class="group_btn">
      <el-button type="success" @click="commitOrder()">提交订单</el-button>
    </div>
  </div>
</template>
 

<script>
import axios from "axios";
import myapi from "../api";
export default {
    name:'Order',
    data(){
      return{
        receiver:{
          name:'',
          phone:'',
          address:''
        }
      }
    },
    methods:{
      commitOrder(){
         if(   this.$cookies.get('status') == 'unlogin' ||
              !this.$cookies.get('status'))
              this.$router.push("/login");
        else{
        axios.post(myapi.order.url,{cart:this.$store.state.cart,receiver:this.receiver})
        .then(res=>{
             if(res.data.code==10){
               	this.$message({
									showClose: true,
									message: '订单提交成功，请支付',
									type: 'success',
									center: true
								});
                this.$store.push({path:'/pay',query:{mouted:this.$store.getters.totalPrice }})
             }
            
        })
        .catch(res=>{
  this.into("购买失败")
        })
        }
      }
    }
}
</script>


 <style scoped>
.cart {
  margin: 50px auto;
  width: 1000px;
}
.group_btn {
  margin-bottom: 30px;
}
.addDialog .el-input {
  width: 90%;
}
.total_warpper {
  text-align: right;
  margin-top: 30px;
}
h3 {
  margin-top: 10px;
}
</style> 